<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">活动统计中心</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>活动统计</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="count-search-key">
                <option value="">-请选择-</option>
                <option value="full">活动单条查询</option>
                <option value="resume">活动简历数量</option>
                <option value="resumes">活动简历明细</option>
                <option value="recruit">活动招聘信息数量</option>
                <option value="recruits">活动招聘信息明细</option>
            </select>&emsp;
            <input id="count-search-value" class="layui-input search-input" type="text" placeholder="请输入活动id"/>&emsp;
            <input id="count-search-values" class="layui-input search-input" type="text" placeholder="请输入公司名称"/>&emsp;
            <button id="count-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="count-table" lay-filter="count-table"></table>
    </div>
</div>

<!-- 表格状态列 -->
<script type="text/html" id="user-tpl-state">
    <input type="checkbox" lay-filter="user-tpl-state" value="{{d.id}}" lay-skin="switch" lay-text="正常|锁定"
           {{d.enabled==true?'checked':''}}/>
</script>

<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var form=layui.form;
        var table = layui.table;
        var config = layui.config;
        $("#count-search-value").hide();
        $("#count-search-values").hide();
        form.on("select", function(data){
            if(data.value=="resume"){
                $("#count-search-value").hide();
                $("#count-search-values").hide();
            }
            else if(data.value==""||data.value==null){
                $("#count-search-value").hide();
                $("#count-search-values").hide();
            }
            else if(data.value=="full"){
                $("#count-search-value").show();
                $("#count-search-values").hide();
            }
            else if(data.value=="resumes"){
                $("#count-search-value").hide();
                $("#count-search-values").hide();
            }
            else if(data.value=="recruit"){
                $("#count-search-value").hide();
                $("#count-search-values").hide();
            }
            else if(data.value=="recruits"){
                $("#count-search-value").hide();
                $("#count-search-values").show();
            }

        });
        // 渲染表格
        table.render({
            elem: '#count-table',
            url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
            method: 'post',
            where: {
                // access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {field: 'id', sort: true, title: 'id'},
                {field: 'title', sort: true, title: '活动名称'},
                {field: 'desc', sort: true, title: '活动描述'},
                {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                        return d.host==null?'无':d.host.username
                    }},
                {field: 'deleted', sort: true, title: '删除状态'},
                {field: 'createTime', sort: true, title: '上传日期'},
                {field: 'companyCount', sort: true, title: '参加公司数'},
                {field: 'resumeCount', sort: true, title: '发布简历总数'},
                {field: 'recruitCount', sort: true, title: '发布招聘信息总数'},
            ]]
        });

        // 搜索按钮点击事件
        $('#count-btn-search').click(function () {
            var key = $('#count-search-key').val();
            var value = $('#count-search-value').val();
            var values= $('#count-search-values').val();
            if(key=="resume"){
                table.render({
                    elem: '#count-table',
                    url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
                    method: 'post',
                    where:
                       {searchKey: key, searchValue: value
                    },
                    page: true,
                    cols: [[
                        {type: 'numbers'},
                        {field: 'id', sort: true, title: 'id'},
                        {field: 'title', sort: true, title: '活动名称'},
                        {field: 'desc', sort: true, title: '活动描述'},
                        {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                                return d.host==null?'无':d.host.username
                            }},
                        {field: 'deleted', sort: true, title: '删除状态'},
                        {field: 'createTime', sort: true, title: '上传日期'},
                        {field: 'companyName', sort: true, title: '公司名称'},
                        {field: 'resumeCount', sort: true, title: '发布简历数量'}
                    ]]
                });

            }
            else if(key==''||key==null){
                table.render({
                    elem: '#count-table',
                    url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
                    method: 'post',
                    where:
                        {searchKey: key, searchValue: value
                        },
                    page: true,
                    cols: [[
                        {type: 'numbers'},
                        {field: 'id', sort: true, title: 'id'},
                        {field: 'title', sort: true, title: '活动名称'},
                        {field: 'desc', sort: true, title: '活动描述'},
                        {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                                return d.host==null?'无':d.host.username
                            }},
                        {field: 'deleted', sort: true, title: '删除状态'},
                        {field: 'createTime', sort: true, title: '上传日期'},
                        {field: 'companyCount', sort: true, title: '参加公司数'},
                        {field: 'resumeCount', sort: true, title: '发布简历总数'},
                        {field: 'recruitCount', sort: true, title: '发布招聘信息总数'},
                    ]]
                });
            }

            else if(key=='full'){
                table.render({
                    elem: '#count-table',
                    url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
                    method: 'post',
                    where:
                        {searchKey: key, searchValue: value
                        },
                    page: true,
                    cols: [[
                        {type: 'numbers'},
                        {field: 'id', sort: true, title: 'id'},
                        {field: 'title', sort: true, title: '活动名称'},
                        {field: 'desc', sort: true, title: '活动描述'},
                        {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                                return d.host==null?'无':d.host.username
                            }},
                        {field: 'deleted', sort: true, title: '删除状态'},
                        {field: 'createTime', sort: true, title: '上传日期'},
                        {field: 'companyCount', sort: true, title: '参加公司数'},
                        {field: 'resumeCount', sort: true, title: '发布简历总数'},
                        {field: 'recruitCount', sort: true, title: '发布招聘信息总数'},
                    ]]
                });
            }

            else if(key=="resumes"){
                table.render({
                    elem: '#count-table',
                    url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
                    method: 'post',
                    where:
                        {searchKey: key, searchValue: value
                        },
                    page: true,
                    cols: [[
                        {type: 'numbers'},
                        {field: 'id', sort: true, title: 'id'},
                        {field: 'title', sort: true, title: '活动名称'},
                        {field: 'desc', sort: true, title: '活动描述'},
                        {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                                return d.host==null?'无':d.host.username
                            }},
                        {field: 'deleted', sort: true, title: '删除状态'},
                        {field: 'createTime', sort: true, title: '上传日期'},
                        {field: 'name', sort: true, title: '简历名称'}
                    ]]
                });
            }

            else if(key=="recruit"){
                table.render({
                    elem: '#count-table',
                    url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
                    method: 'post',
                    where:
                        {searchKey: key, searchValue: value
                        },
                    page: true,
                    cols: [[
                        {type: 'numbers'},
                        {field: 'id', sort: true, title: 'id'},
                        {field: 'title', sort: true, title: '活动名称'},
                        {field: 'desc', sort: true, title: '活动描述'},
                        {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                                return d.host==null?'无':d.host.username
                            }},
                        {field: 'deleted', sort: true, title: '删除状态'},
                        {field: 'createTime', sort: true, title: '上传日期'},
                        {field: 'companyName', sort: true, title: '公司名称'},
                        {field: 'companyName', sort: true, title: '发布招聘信息数量'},
                    ]]
                });
            }


            else if(key=="recruits"){
                table.render({
                    elem: '#count-table',
                    url: config.base_server + 'api-count/statistics/fullSearch'+'?access_token='+config.getToken().access_token,
                    method: 'post',
                    where:
                        {searchKey: key, searchValue: values
                        },
                    page: true,
                    cols: [[
                        {type: 'numbers'},
                        {field: 'id', sort: true, title: 'id'},
                        {field: 'title', sort: true, title: '活动名称'},
                        {field: 'desc', sort: true, title: '活动描述'},
                        {field: 'hostName', sort: true, title: '上传者',templet:function (d) {
                                return d.host==null?'无':d.host.username
                            }},
                        {field: 'deleted', sort: true, title: '删除状态'},
                        {field: 'createTime', sort: true, title: '上传日期'},
                        {field: 'companyName', sort: true, title: '公司名称'},
                        {field: 'recruitName', sort: true, title: '职位名称'},
                    ]]
                });
            }


        });

    });
</script>